package com.example.zytj.controller;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import com.example.zytj.mapper.IReadRoomMapper;
import com.example.zytj.model.ReadRoom;

import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("room")
@ApiOperation("资源室管理")
public class ReadRoomController {
    @Resource
    private IReadRoomMapper mapper;

    @ApiOperation(value = "查询资源室", notes = "资源室列表")
    @GetMapping
    public Map<String, Object> findRoom() {
        Map<String, Object> map = new HashMap<>();
        map.put("data", mapper.selectList(null));
        return map;
    }

    @ApiOperation(value = "新增资源室")
    @PostMapping
    public int add(ReadRoom room) {
        return mapper.insert(room);
    }

    @ApiOperation(value = "修改资源室信息")
    @PutMapping
    public int edit(ReadRoom room) {
        return mapper.updateById(room);
    }

    @ApiOperation(value = "删除资源室", notes = "逻辑删除")
    @DeleteMapping
    public int del(int id) {
        ReadRoom room = new ReadRoom();
        room.setId(id);
        room.setRemark("已删除");
        return mapper.updateById(room);
    }
}
